package com.bt.config;

import com.bt.properties.AliOssProperties;
import com.bt.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description TODO
 * @Author 张传康
 * @Date 2023-05-02 19:53
 */
@Configuration
@Slf4j
public class AliOSSConfiguration {

    /**
     * 将AliOssUtil创建放入spring容器
     * @param aliOssProperties
     * @return
     */
    @Bean
    @ConditionalOnMissingBean //如果容器中没有当前这个对象才会运行当前方法将返回值加入spring容器
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){
        return new AliOssUtil(aliOssProperties.getEndpoint(),aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),aliOssProperties.getBucketName());
    }
}
